#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mm.h>


#define PCPU_COUNT 4

static void __percpu *pcpu_var[PCPU_COUNT];

static void clean_pcpu(void)
{
	int i;

	for (i = 0; i < PCPU_COUNT; i++) {
		if (pcpu_var[i] == NULL)
			break;

		free_percpu(pcpu_var[i]);
	}
}

static int __init pcpu_init(void)
{
	int i;

	for (i = 0; i < PCPU_COUNT; i++) {
		pcpu_var[i] = alloc_percpu(unsigned long);
		if (!pcpu_var[i]) {
			pr_err("__alloc_percpu failed, i=%d\n", i);
			goto err;
		}
	}

	return 0;

err:
	return -1;
}

static void __exit pcpu_exit(void)
{
	pr_info("%s...\n", __func__);
	clean_pcpu();
}

module_init(pcpu_init);
module_exit(pcpu_exit);
MODULE_LICENSE("GPL");
